<template>
    <div>
        <div class="breadcrumb-box">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>生产代工</el-breadcrumb-item>
                <el-breadcrumb-item>新增生产代工</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="line">
            <img :src="$global.Image.icon_goods_line" />
        </div>
        <div class="container">
            <div class="line-ti">
                <div>新增生产代工</div>
            </div>
            <div class="write-info-tit">
                填写生产代工信息
            </div>
            <el-form ref="form" :model="form" label-width="120px" :rules="rules" class="rule-form">
                <el-form-item label="联系人：" prop="contacts">
                    <el-input v-model="form.contacts" placeholder="请输入联系人"></el-input>
                </el-form-item>
                <el-form-item label="联系电话：" prop="mobile">
                    <el-input v-model="form.mobile" placeholder="请输入联系电话"></el-input>
                </el-form-item>
                <el-form-item label="商品名称：" prop="name">
                    <el-input v-model="form.name" placeholder="请输入商品名称"></el-input>
                </el-form-item>
                <el-form-item label="代工要求：" prop="content">
                    <el-input type="textarea" v-model="form.content" placeholder="请输入代工要求"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <div class="file">
                        <div class="file-left">附件</div>
                        <div class="td-f1">
                            <div class="el-form-item__content upload-img">
                                <el-upload
                                    ref="upload"
                                    :action="url"
                                    :data="qiniuData"
                                    :on-preview="handlePictureCardPreview"
                                    :before-upload="beforeAvatarUpload"
                                    :on-remove="handleRemove"
                                    :on-success="handleAvatarSuccess"
                                    :multiple="true"
                                    name="files[]"
                                >
                                    <el-button size="small" type="primary">点击上传</el-button>
                                </el-upload>
                            </div>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" @click="onSubmit('form')">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import { articlePublish } from "@api/order";
import uploadQiniu from "@/mixins/uploadQiniu"
export default {
    mixins: [uploadQiniu],
    data() {
        return {
            type: 2,
            form: {
                contacts: "",//联系人
                mobile: "",// 联系电话
                name: "",//商品名称
                brand: "",//品牌品牌
                content: "",//型号
                content1: "",//参数
            },
            files: [],
            rules: {
                contacts: [
                    {
                        required: true,
                        message: "请输入联系人",
                        trigger: "blur",
                    },
                ],
                mobile: [
                    {
                        required: true,
                        message: "请输入联系电话",
                        trigger: "blur",
                    },
                ],
                name: [
                    {
                        required: true,
                        message: "请输入商品名称",
                        trigger: "blur",
                    },
                ],
                content: [
                    {
                        required: true,
                        message: "请输入规格",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    methods: {
        onSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        async submit() {
            let imgs  = []
            imgs = this.formatFile(this.fileList)
            if (!imgs.length) {
                that.$dialog.error('请上传附件')
                return
            };
            try {
                let that = this,
                    params = that.form;
                    params.type = that.type
                    params.files = JSON.stringify(imgs)
                console.log('params', params)
                articlePublish(params)
                    .then(function (res) {
                        if (res.status != 200) {
                            that.$dialog.toast({ mes: res.msg });
                            return;
                        }
                        that.$dialog.toast({ mes: res.msg });
                        that.$router.go(-1)
                    })
                    .catch((err) => {
                        that.$dialog.error(err.msg);
                    });
            } catch (e) {
                this.$dialog.error(e.msg);
            }
        },
    },
    mounted() {},
};
</script>

<style scoped  lang="scss">
.line {
    width: 1200px;
    margin: 0 auto 30px;
    img {
        display: block;
        width: 100%;
    }
}
.file {
    width: 520px;
    background: #ffffff;
    border-radius: 5px;
    box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    padding: 10px 25px;
    box-sizing: border-box;
    .file-left {
        font-size: 16px;
        font-weight: bold;
        text-align: left;
        color: #333333;
        width: 60px;
        flex-shrink: 0;
    }
    .file-right {
        flex: 1;
        display: flex;
        align-items: center;
        .no-file {
            font-size: 13px;
            color: #999999;
            margin-right: 10px;
        }
        .have-file {
            font-size: 13px;
            color: #333333;
            margin-right: 10px;
        }
        .choose-file {
            width: 88px;
            height: 24px;
            background: #e2edff;
            border: 1px solid #13479d;
            border-radius: 2px;
            font-size: 12px;
            text-align: center;
            color: #13479d;
            line-height: 24px;
            cursor: pointer;
        }
    }
}
.el-button--success:focus,
.el-button--success:hover {
    background: #da213d;
    border-color: #da213d;
}
.el-button--success {
    width: 230px;
    background: #da213d;
    border-radius: 5px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    color: #ffffff;
    line-height: 18px;
    box-sizing: border-box;
    height: 50px;
    border-color: #da213d;
    &:hover {
        background: #da213d;
        border-color: #da213d;
    }
    &:active {
        background: #da213d;
        border-color: #da213d;
    }
}
.el-input {
    width: 520px;
}
.el-form-item {
    margin-top: 20px;
}
.el-form-item__label {
    text-align: right;
    font-size: 15px;
    // font-weight: bold;
    padding-left: 25px;
}
.el-textarea__inner {
    width: 520px;
    resize: none;
    height: 80px;
}
.write-info-tit {
    position: relative;
    font-size: 18px;
    font-weight: bold;
    height: 90px;
    padding-left: 24px;
    display: flex;
    align-items: center;
    color: #333333;
    border-bottom: 1px dashed #eaecfa;
    &::before {
        border-radius: 100%;
        border: 3px solid #da213d;
        position: absolute;
        width: 5px;
        height: 5px;
        left: 0;
        top: 0;
        bottom: 0;
        margin: auto 0;
        content: "";
    }
}
.line-ti {
    width: 100%;
    border-bottom: 1px solid #dbdbdb;
    display: flex;
    > div {
        color: #da213d;
        font-size: 18px;
        // border-bottom: 3px solid $color;
        // width: 112px;
        line-height: 36px;
        font-weight: bold;
        position: relative;
        &::before {
            position: absolute;
            bottom: 0;
            left: 0;
            content: "";
            width: 72px;
            height: 3px;
            background: #da213d;
        }
    }
}
</style>